package com.daoshun.common;

import javax.servlet.http.HttpServletRequest;

public class RequestParamter {

	/**
	 * 
	 * @param request
	 *            httpServletRequest
	 * @param key
	 * @return String
	 */
	public static String getStringValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		if (CommonUtils.isEmptyString(value)) {
			return null;
		}
		return value;
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return Integer 非int类型返回空
	 */
	public static Integer getIntegerValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		if (CommonUtils.isEmptyString(value)) {
			return null;
		}
		return CommonUtils.parseInt(value, 0);
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return int 非int类型或空返回0
	 */
	public static int getIntValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		return CommonUtils.parseInt(value, 0);
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return Double 非Double类型返回空
	 */
	public static Double getDoubleValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		if (CommonUtils.isEmptyString(value)) {
			return null;
		}
		return CommonUtils.parseDouble(value, 0);
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return double 非double类型或空返回0
	 */
	public static double getdoubleValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		return CommonUtils.parseDouble(value, 0);
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return Float 非Float类型返回空
	 */
	public static Float getFloatValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		if (CommonUtils.isEmptyString(value)) {
			return null;
		}
		return CommonUtils.parseFloat(value, 0);
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return float 非float类型或空返回0
	 */
	public static float getfloatValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		return CommonUtils.parseFloat(value, 0);
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return Long 非Long类型返回空
	 */
	public static Long getLongValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		if (CommonUtils.isEmptyString(value)) {
			return null;
		}
		return CommonUtils.parseLong(value, 0);
	}

	/**
	 * 
	 * @param request
	 * @param key
	 * @return long 非long类型或空返回0
	 */
	public static long getlongValue(HttpServletRequest request, String key) {
		String value = request.getParameter(key);
		return CommonUtils.parseLong(value, 0);
	}

}
